// pages/user/cheapShop/cheapShop.js
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    cardArr: [0, 1, 2, 3, 4, 5],

  },

  //添加店铺优惠
  makeCheapShop:function(){
    wx.navigateTo({
      url: '../makeCheapShop/makeCheapShop',
    })
  },

  //删除点击
  deleteClick:function(e){
    var that = this;
    app.post('coupon/del', {id: e.currentTarget.id}).then((res) => {
      console.log('success');
      console.log(res);
      if (res.code == 0) {
        that.getData();
      } else {
        wx.showModal({
          title: '温馨提示',
          content: res.msg,
          showCancel: false,
        })
      }
    }).catch((errMsg) => {
      console.log('fail');
      console.log(errMsg + '失败');
    })
  },

  //详情点击
  cheapShopClick:function(e){
    console.log('详情' + e.currentTarget.id);
    wx.navigateTo({
      url: '../../home/shopCheapDetail/shopCheapDetail?id=' + e.currentTarget.id +'&stype=1',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getData();
  },

  getData: function () {
    var that = this;
    app.post('coupon/queryListForShop', {openId: wx.getStorageSync('userInfo').userId
    }).then((res) => {
      console.log('success');
      console.log(res);
      if (res.code == 0) {
        that.setData({
          cardArr: res.resultData,
        })
      } else {
        wx.showModal({
          title: '温馨提示',
          content: res.msg,
          showCancel: false,
        })
      }
    }).catch((errMsg) => {
      console.log('fail');
      console.log(errMsg + '失败');
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})